1 using UnityEngine;
2 using
System.Collections;
3
4 public
class ActionRepeat : DelegateAction {
5
6     
public const int FOREVER = -1;
7
8     
private int repeatCount, executedCount;
9     
private bool finished;
10
11     
public ActionRepeat() { }
12
13     
public ActionRepeat(int repeatCount, Action repeateAction){
14         
this.repeatCount = repeatCount;
15         
this.action = repeateAction;
16     }
17
18     
protected override bool UpdateDelegate(float delta)
19     {
20         
if (executedCount == repeatCount) return true;
21         
if (action.Act(delta))
22         {
23             
if (finished) return true;
24             
if (repeatCount > 0) executedCount++;
25             
if (executedCount == repeatCount) return true;
26             
if (action != null) action.restart();
27         }
28         
return false;
29     }
30
31     
public void finish()
32     {
33         finished =
true;
34     }
35
36     
public override void restart()
37     {
38         
base.restart();
39         executedCount =
0;
40         finished =
false;
41     }
42
43     
public void setCount(int count)
44     {
45         
this.repeatCount = count;
46     }
47
48     
public int getCount()
49     {
50         
return this.repeatCount;
51     }
52 }



Trò chơi đua xe động vật trong UNITY Engine 114.945 lượt xem

Gõ tìm kiếm nhanh...